package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.NecessaryVariableAddDTO;
import org.jsola.hr.dto.NecessaryVariableUpdateDTO;
import org.jsola.hr.entity.NecessaryVariableDO;
import org.jsola.hr.query.NecessaryVariableQuery;
import org.jsola.hr.service.INecessaryVariableService;
import org.jsola.hr.vo.NecessaryVariableVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工必填信息关联变量
 *
 * @author zhr
 */
@Component
public class NecessaryVariableTestHelper extends BaseTestHelper {
    
    @Autowired
    private INecessaryVariableService necessaryVariableService;

    /**
     * 生成add测试数据
     * @return NecessaryVariableAddDTO
     */
    public NecessaryVariableAddDTO getNecessaryVariableAddDTO(){
        NecessaryVariableAddDTO necessaryVariableAddDTO = new NecessaryVariableAddDTO();
        necessaryVariableAddDTO.setTemplateId(SafeKit.getLong(getRandomValue("bigint",11)));
        necessaryVariableAddDTO.setNecessaryId(getRandomValue("varchar",32));
        return necessaryVariableAddDTO;
    }


    /**
     * 生成update测试数据
     * @return NecessaryVariableUpdateDTO
     */
    public NecessaryVariableUpdateDTO getNecessaryVariableUpdateDTO(NecessaryVariableVO necessaryVariableVO){
        return necessaryVariableService.selectDOById(necessaryVariableVO.getId(), SITE_ID).to(NecessaryVariableUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return NecessaryVariableQuery
     */
    public NecessaryVariableQuery getNecessaryVariableQuery() {
        NecessaryVariableQuery necessaryVariableQuery = new NecessaryVariableQuery();
        List<NecessaryVariableDO> necessaryVariableDOList = necessaryVariableService.list(new NecessaryVariableDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(necessaryVariableDOList)) {
            NecessaryVariableDO necessaryVariableDO = necessaryVariableDOList.get(0);
            necessaryVariableQuery = necessaryVariableDO.to(NecessaryVariableQuery.class);
        }
        return necessaryVariableQuery;
    }

    /**
     * 保存示例
     * @return NecessaryVariableVO
     */
    public NecessaryVariableVO saveNecessaryVariableExample(){
        NecessaryVariableAddDTO addDTO = this.getNecessaryVariableAddDTO();
        NecessaryVariableVO necessaryVariableVO = necessaryVariableService.save(addDTO,buildTokenUser());
        return necessaryVariableVO;
    }


}

